package traveldream.ejb.entities;

import java.io.Serializable;

import javax.persistence.*;

import traveldream.ejb.DTO.ExcursionDTO;

import java.util.Date;
import java.util.List;


/**
 * The persistent class for the excursion database table.
 * 
 */
@Entity
@NamedQueries({
@NamedQuery(name="Excursion.findAll", query="SELECT e FROM Excursion e WHERE e.Invalid=false"),
@NamedQuery(name="Excursion.checkAvl", query="SELECT e FROM Excursion e WHERE e.Invalid=false AND e.available_Places>= :n AND e.date> :dep_date AND e.date< :arr_date AND e.city= :arr_place")
})
public class Excursion implements Serializable {
	private static final long serialVersionUID = 1L;
	public static final String FIND_ALL = "Excursion.findAll";
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;

	@Column(name="`Available Places`")
	private int available_Places;

	private String city;

	@Temporal(TemporalType.DATE)
	private Date date;

	private String description;

	private String duration;

	private String name;

	private int price;

	private String type;

	//bi-directional many-to-one association to DefaultPackage
	@OneToMany(mappedBy="excursion")
	private List<DefaultPackage> defaultPackages;
	
	private boolean Invalid;
	
	@OneToMany(mappedBy="Excursion")
	private List<CustomizedPackage> customPackages;

	@OneToMany(mappedBy="Excursion")
	private List<GiftList> giftedExcursion;
	
	
	public List<GiftList> getGiftedExcursion() {
		return giftedExcursion;
	}

	public void setGiftedExcursion(List<GiftList> giftedExcursion) {
		this.giftedExcursion = giftedExcursion;
	}

	public List<CustomizedPackage> getCustomPackages() {
		return customPackages;
	}

	public void setCustomPackages(List<CustomizedPackage> customPackages) {
		this.customPackages = customPackages;
	}

	public boolean isInvalid() {
		return Invalid;
	}

	public void setInvalid(boolean invalid) {
		Invalid = invalid;
	}

	public Excursion(){
	}
	
	public Excursion(ExcursionDTO eDTO){
		this.city=eDTO.getCity();
		this.date=eDTO.getDate();
		this.description = eDTO.getDescription();
		this.duration = eDTO.getDuration();
		this.name = eDTO.getName();
		this.price = eDTO.getPrice();
		this.type = eDTO.getType();
		this.available_Places = eDTO.getAvailablePlaces();
		this.Invalid=false;
	}
	
	public ExcursionDTO convertToDTO(){
		ExcursionDTO eDTO = new ExcursionDTO();
		eDTO.setId(id);
		eDTO.setName(name);
		eDTO.setAvailablePlaces(available_Places);
		eDTO.setCity(city);
		eDTO.setDate(date);
		eDTO.setDescription(description);
		eDTO.setDuration(duration);
		eDTO.setPrice(price);
		eDTO.setType(type);
		return eDTO;
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getAvailable_Places() {
		return this.available_Places;
	}

	public void setAvailable_Places(int available_Places) {
		this.available_Places = available_Places;
	}

	public String getCity() {
		return this.city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public Date getDate() {
		return this.date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDuration() {
		return this.duration;
	}

	public void setDuration(String duration) {
		this.duration = duration;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getPrice() {
		return this.price;
	}

	public void setPrice(int price) {
		this.price = price;
	}

	public String getType() {
		return this.type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public List<DefaultPackage> getDefaultPackages() {
		return this.defaultPackages;
	}

	public void setDefaultPackages(List<DefaultPackage> defaultPackages) {
		this.defaultPackages = defaultPackages;
	}

	public DefaultPackage addDefaultPackage(DefaultPackage defaultPackage) {
		getDefaultPackages().add(defaultPackage);
		defaultPackage.setExcursion(this);

		return defaultPackage;
	}

	public DefaultPackage removeDefaultPackage(DefaultPackage defaultPackage) {
		getDefaultPackages().remove(defaultPackage);
		defaultPackage.setExcursion(null);

		return defaultPackage;
	}

}